/*
 * Copyright (c) 2025, 廖树财, <study_2030@163.com>
 *
 * PHS2.0-YCYW is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2     
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
#pragma once
#include "define.h"
#include "JsonParser.h"
#include "zlog.h"
#include <pthread.h>
#include "common.h"
#include <sys/stat.h>

typedef struct container_devices_map
{
    char key[50];
    char value[100];
} container_devices_map;

typedef struct container_volumn
{
    char path[130];
    int size;
    int visible;
} container_volumn;

typedef struct stru_ST_IOTA_CONTAINER_INFO
{
    char *containerId;
    char *containerName;
    char *containerHyperv;
    char *srcContainerId;
    char *srcContainerName;
    char *fileId;
    int cpuCount;
    int cpuPeriod;
    int cpuQuota;
    int memorySize;
    int storageSize;
    char *imageName;
    char *imageTag;
    container_devices_map *devices;
    int devicecount;
    container_volumn *volumes;
    int volumecount;
    char *ip;
} IOTA_CONTAINER_INFO;

typedef struct stru_ST_IOTA_CONTAINER_RES
{
    char *containerId;
    char *srcContainerId;
} IOTA_CONTAINER_RES;

typedef struct stru_ST_IOTA_CONTAINER_CTRL
{
    char *containerId;
    char *containerName;
    char *containerHyperv;
    char *fileId;
    char *filename;
} IOTA_CONTAINER_CTRL;

typedef struct stru_ST_IOTA_CONTAINER_DOWNLOAD_PROGRESS
{
    char *fileid;
} IOTA_CONTAINER_DOWNLOAD_PROGRESS;

typedef struct stru_IOTA_CON_DOWNLOAD
{
    char *fileName;
    // char *fileLink;
    char *fileId;
    // char *accessToken;
    char *digestAlgorithm;
    char *digest;
    char *fileType;
    int size;
} IOTA_CON_DOWNLOAD;

typedef struct stru_IOTA_CON_DOWNLOAD_PROGRESS_RES
{
    char *appId;
    char *filename;
    long totalSize;
    long size;
    char *process;
    int errorCode;
} IOTA_CON_DOWNLOAD_PROGRESS_RES;

extern char *DOCKER_PATH;

bool send_progress_V3(int code, int progress, ST_IOTA_LOG_RES *progressDecs);

bool JsonToStruct_ContainerInstall(char *pcJson, ST_IOTA_LOG *pcStatusDecs);

int StructToJson_ContainerInstallRes(char **pcJson, ST_IOTA_LOG_RES *pcStatusDecs);

bool JsonToStruct_ContainerCtrl(char *pcJson, ST_IOTA_LOG *pcStatusDecs);

bool StructToJson_ContainerDownLoadRes(char **pcJson, ST_IOTA_LOG_RES *pcStatusDecs);

int container_download(char *pJson);

int container_download_pthread(char *pJson);

int container_install(char *pJson);

int container_clone(char *pJson);

int container_ctrl(char *pJson, int action);

int container_command(char *pcJson);
